<?php
/**
 * Author: Traveler
 * Time  : 2021/10/12 21:59
 */

namespace app\controller\crm\v1;


use app\ErrorCode;
use app\service\IcafeWanService;
use sunshine\basic\RestController;
use sunshine\exceptions\ApiException;
use think\App;
use think\Response;

class IcafeWan extends RestController
{
    /**
     * IcafeWan constructor.
     *
     * @param App             $app
     * @param IcafeWanService $service
     */
    public function __construct(App $app, IcafeWanService $service)
    {
        parent::__construct($app);
        $this->service = $service;
    }

    /**
     * 获取列表(重写)
     *
     * @return Response
     */
    public function select(): Response
    {
        $icafe_id = $this->request->get('icafe_id');
        if (!$icafe_id) {
            throw new ApiException(ErrorCode::MISSING_PARAMETERS);
        }

        return parent::select();
    }

    /**
     * 创建(重写)
     *
     * @param string|null $validate 验证器名称
     * @return Response
     */
    public function create(?string $validate = null): Response
    {
        $icafe_id = $this->request->post('icafe_id');
        if (!$icafe_id) {
            throw new ApiException(ErrorCode::MISSING_PARAMETERS);
        }

        return parent::create('IcafeTechValidate.wan');
    }

    /**
     * 修改(重写)
     *
     * @param int         $id       ID
     * @param string|null $validate 验证器名称
     * @return Response
     */
    public function update(int $id, ?string $validate = null): Response
    {
        // 使用数据验证
        return parent::update($id, 'IcafeTechValidate.wan');
    }
}